package com.habdqn.servlet.demo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = {"/myServlet"},name = "myServlet",
        initParams = {@WebInitParam(name = "encoding",value = "gbk")})
public class MyServlet extends HttpServlet {



    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(request.getCharacterEncoding());

        String str = request.getParameter("para1");
        System.out.println("参数1："+str);
        PrintWriter out = response.getWriter();
        out.print("<h1>DoGet响应信息</h1>");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        System.out.println(this.getInitParameter("encoding"));
//        String name = request.getParameter("name");
//        System.out.println("name:"+name);
        System.out.println(request.getCharacterEncoding());
        response.sendRedirect("/");
    }
}
